﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 录入可选值管理
//最后修改: 李城 2010-10-12 新增获取可选值 树形结构 
using System;
using System.Collections.Generic;
using System.Text;


using TRPOP.CMS.Model;
using TRPOP.CMS.DALFactory;
using TRPOP.Common;

namespace TRPOP.CMS.Business
{
    public class FormInputValueManage
    {

        private IFormInputValueDAL Idal;
        public FormInputValueManage()
        {
            Idal = DataAccess.CreateFormInputValueDAL();
        }

        #region 保存 Save
        ///	<summary>
        ///	保存
        ///	</summary>
        ///	<param name="FormInputValueInfo"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult Save(FormInputValueInfo info)
        {
            return Idal.Save(info);
        }

        #endregion

        #region 获取实体 GetInfoById
        ///	<summary>
        ///	获取实体
        ///	</summary>
        ///	<param name="formInputValueId"></param>
        ///	<returns>FormInputValueInfo</returns>
        public FormInputValueInfo GetInfoById(int id)
        {
            return Idal.GetInfoById(id);
        }
        #endregion

        #region 删除 DeleteInfoById
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="id"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return Idal.DeleteInfoByIds(id.ToString());
        }
        #endregion

        #region 删除 DeleteInfoByIds
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="ids"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            return Idal.DeleteInfoByIds(ids);
        }
        #endregion

        #region 自定义列表（无分页） GetListByCondition
        ///	<summary>
        ///	自定义列表（无分页）
        ///	</summary>
        ///	<param name="topn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="condition">自定义条件，要以And开头</param>
        ///	<param name="orderby">排序，不需要Order by </param>
        ///	<returns>List<FormInputValueInfo></returns>
        public List<FormInputValueInfo> GetListByCondition(int topn, string condition, string orderby)
        {
            return Idal.GetListByCondition(topn, condition, orderby);
        }
        #endregion

        #region 自定义列表（分页） GetListByPager
        ///	<summary>
        ///	自定义列表（分页）
        ///	</summary>
        ///	<returns>List<FormInputValueInfo></returns>
        public List<FormInputValueInfo> GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            return Idal.GetListByPager(pageNumber, pageSize, condition, orderby, out  recordCount);
        }
        #endregion

        #region 获取可选值 树形结构

        /// <summary>
        /// 获取可选值的树形结构
        /// </summary>
        /// <param name="FormInputValueTypeId">可选值类型id</param>
        /// <param name="ParentId">可选值的父id</param>
        /// <param name="level">预设的级数</param>
        /// <param name="Condition">外加的条件</param>
        /// <returns></returns>
        public List<FormInputValueInfoWithLevel> GetFormInputValueListTree(int FormInputValueTypeId, int ParentId, int level, string Condation)
        {
            return Idal.GetFormInputValueListTree(FormInputValueTypeId, ParentId, level, Condation);
        }

        #endregion

        #region 获取可选值的名字
        public string GetValueNameByIDs( string IDs)
        {
            IDs = IDs.Replace("'","");
            List<FormInputValueInfo> FormInputValueInfoList = GetListByCondition(0, "  AND FormInputValueId IN("+IDs+") ", " FormInputValueId ASC ");
            string strValueName = "";
            foreach (FormInputValueInfo info in FormInputValueInfoList)
            {
                strValueName += info.Name+"  ";
            }
            return strValueName;
        }
        #endregion

    }
}
